export function minDepth(root: TreeNode | null): number {
    if (!root) return 0
    const tempArr: TreeNode[] = [root]
    let deep = 0
    let res = 0
    while (tempArr.length) {
        const len = tempArr.length
        deep++
        let isBreak = false
        for (let index = 0; index < len; index++) {
            const node = tempArr.shift()
            if (!node?.left && !node?.right) {
                res = deep
                isBreak = true
                break;
            }
            if (node.left) tempArr.push(node.left)
            if (node.right) tempArr.push(node.right)
        }
        if (isBreak) break;
    }
    return res
};